package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

func VersionCmd() *cobra.Command {
	var versionCmd = &cobra.Command{
		Use:   "version",
		Short: "Print the version number of Hugo",
		Long:  `All software has versions. This is Hugo's`,
		// 子命令定义了自己的 Persistent*Run 函数，则不会继承父命令的 Persistent*Run 函数
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			fmt.Println("version PersistentPreRun")
		},
		PreRun: func(cmd *cobra.Command, args []string) {
			fmt.Println("version PreRun")
		},
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println("Hugo Static Site Generator v0.9 -- HEAD")
		},
		// 使用内置的验证函数，位置参数多于 2 个则报错
		Args: cobra.MaximumNArgs(2), // go run main.go version a b
	}

	return versionCmd
}
